package com.shure.surdes.modules.survey.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shure.surdes.common.query.condition.Condition;
import com.shure.surdes.common.result.R;
import com.shure.surdes.common.result.Result;
import com.shure.surdes.modules.survey.domain.AnswerJson;
import com.shure.surdes.modules.survey.query.AnswerJsonQuery;
import com.shure.surdes.modules.survey.service.IAnswerJsonService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问卷答案结果jsonController
 *
 * @author Shure
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/survey/json")
public class AnswerJsonController {
    @Autowired
    private IAnswerJsonService answerJsonService;

    @GetMapping("/page")
    public R page(AnswerJsonQuery query) {
        LambdaQueryWrapper<AnswerJson> wrapper = Condition.getLambdaQueryWrapper1(query);
        wrapper.eq(AnswerJson::getStatus, 1).eq(AnswerJson::getDataState, 1);
        Page<AnswerJson> page = answerJsonService.page(query.getPage(), wrapper);
        return Result.ok(page);
    }

    /**
     * 查询问卷答案结果json列表
     */
    @GetMapping("/list")
    public R list(AnswerJson answerJson) {
        List<AnswerJson> list = answerJsonService.selectAnswerJsonList(answerJson);
        return Result.ok(list);
    }

    /**
     * 导出问卷答案结果json列表
     */
    @GetMapping("/export")
    public R export(AnswerJson answerJson) {
        List<AnswerJson> list = answerJsonService.selectAnswerJsonList(answerJson);
        return Result.ok(list);
    }

    /**
     * 获取问卷答案结果json详细信息
     */
    @GetMapping(value = "/{anId}")
    public R getInfo(@PathVariable("anId") Long anId) {
        return Result.success(answerJsonService.selectAnswerJsonByAnId(anId));
    }

    /**
     * 新增问卷答案结果json
     */
    @PostMapping
    public R add(@RequestBody AnswerJson answerJson) {
        answerJsonService.insertAnswerJson(answerJson);
        return Result.success(answerJson.getAnId());
    }

    /**
     * 修改问卷答案结果json
     */
    @PutMapping
    public R edit(@RequestBody AnswerJson answerJson) {
        return Result.success(answerJsonService.updateAnswerJson(answerJson));
    }

    /**
     * 删除问卷答案结果json
     */
    @DeleteMapping("/{anIds}")
    public R remove(@PathVariable Long[] anIds) {
        return Result.success(answerJsonService.deleteAnswerJsonByAnIds(anIds));
    }
}
